<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:p="http://primefaces.org/ui"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:pe="http://primefaces.org/ui/extensions">

    <pe:head>
        <title>#{bundle.coralAttrib}</title>
        <link href="./resources/css/default.css" rel="stylesheet" type="text/css" />
        
    </pe:head>
    <h:body>
        
    <ui:composition>    
            <h:form  >
               <script type="text/javascript">  
                    function handleSaveCoralAttrib(xhr, status, args) {  
                        if(args.validationFailed || !args.success) {  
                            jQuery('#dialog').effect("shake", { times:3 }, 100);  
                        } else {  
                            dlgCoralAttrib.hide();  
                        }  
                    }

                    function handleDeleteCoralAttrib(xhr, status, args) {  
                        if(args.validationFailed || !args.success) {  
                            jQuery('#dialog').effect("shake", { times:3 }, 100);  
                        } else {  
                            dlgDelCoralAttrib.hide();  
                        }  
                    }
                    
                </script>

                <p:toolbar>
                    <p:toolbarGroup align="left">
                         <p:commandButton value="#{bundle.btnNew}" icon="ui-icon-document" 
                                         action="#{coralAttribBean.newData()}" oncomplete="dlgCoralAttrib.show();" 
                                         update=":#{utilityBean.findClientId('displayCoralAttrib')}" process="@this">
                            <pe:resetEditableValues for="displayCoralAttrib" />  
                        </p:commandButton>   
                  
                        <p:commandButton value="#{bundle.btnOpen}" oncomplete="dlgCoralAttrib.show()"
                                         actionListener="#{coralAttribBean.openData()}"
                                         icon="ui-icon-disk" 
                                         update=":#{utilityBean.findClientId('displayCoralAttrib')}" /> 

                        <p:commandButton type="button" value="#{bundle.btnDelete}" icon="ui-icon-trash"
                                         onclick="dlgDelCoralAttrib.show()"
                                         update=":#{utilityBean.findClientId('displayCoralAttrib')}" /> 
                    </p:toolbarGroup>
                </p:toolbar>

                <p:dataTable var="coralAttrib" value="#{coralAttribBean.coralAttribs}" id="dtCoralAttribs"
                             selection="#{coralAttribBean.selectedData}" selectionMode="single" rowKey="#{coralAttrib.corattribId}" 
                             resizableColumns="true" rowIndexVar="noUrut" >
                    
                    <p:column style="width:11px;" >
                        <f:facet name="header">No</f:facet>
                        <h:outputText value="#{noUrut+1}" />
                    </p:column>
                    
                    <p:column style="width:150px;" sortBy="#{coralAttrib.attributeName}">
                        <f:facet name="header">#{bundle.attributeName}</f:facet>
                        <h:outputText value="#{coralAttrib.attributeName}" />
                    </p:column>
                    
                    <p:column style="width:auto">
                        <f:facet name="header">#{bundle.collateral}</f:facet>
                        <h:outputText value="#{coralAttribBean.selectItemValueOf(coralAttrib.coralId)}" />
                    </p:column>
                </p:dataTable>
           
                <p:confirmDialog message="#{bundle.confirmDelete}" appendToBody="true" 
                                 header="#{bundle.confirmDeleteHeader}" severity="alert" widgetVar="dlgDelCoralAttrib">  
                    <p:commandButton value="#{bundle.btnYes}" update=":#{utilityBean.findClientId('dtCoralAttribs')}" 
                                     oncomplete="handleDeleteCoralAttrib(xhr, status, args)"  
                                     actionListener="#{coralAttribBean.delete()}" />  
                    <p:commandButton value="#{bundle.btnCancel}" onclick="dlgDelCoralAttrib.hide()" type="button" />   
                </p:confirmDialog> 
                
                </h:form>
        
                <p:dialog header="#{bundle.coralAttrib}" widgetVar="dlgCoralAttrib" closable="true" dynamic="true" modal="true" appendToBody="true">
                    <p:ajax event="close" listener="#{coralAttribBean.handleClose}"/>
                    <h:form>
                    <h:panelGrid id="displayCoralAttrib" columns="3" styleClass="addELIT" cellpadding="0" cellspacing="5">
                        <h:outputLabel value= "#{bundle.globalName}" /><h:outputLabel value= ":" />
                        <h:panelGrid columns="2" cellpadding="0" cellspacing="0" rendered="#{coralAttribBean.unsaveData!=null}">
                            <p:inputText value="#{coralAttribBean.unsaveData.attributeName}" 
                                     required="true" label="#{bundle.attributeName}" style="width: 170px"
                                     requiredMessage="#{bundle.attributeName} #{bundle.requiredInput}"
                                     id="attribAttributeName" >
                                <p:ajax event="keyup" update="msgattribAttributeName" process="@this"/>
                            </p:inputText>
                            <p:message id="msgattribAttributeName" for="attribAttributeName" display="icon" />
                        </h:panelGrid>

                        <h:outputLabel style="padding: 0 15px 0 0" value= "#{bundle.collateral}" /><h:outputLabel value= ":" />
                        <p:selectOneMenu value="#{coralAttribBean.unsaveData.coralId}" style="width: 170px" rendered="#{coralAttribBean.unsaveData!=null}"
                                         required="true" requiredMessage="#{bundle.collateral} #{bundle.requiredInput}" id="attribCoral" >
                            
                            <f:selectItems value="#{coralAttribBean.avblCoral}" />
                        </p:selectOneMenu>
                    </h:panelGrid>

                    <h:panelGrid cellpadding="0" styleClass="pComBtnSTDR">
                        <f:facet name="footer">
                            <p:commandButton value="#{bundle.btnSave}" icon="ui-icon-disk" actionListener="#{coralAttribBean.save()}"
                                             update=":#{utilityBean.findClientId('dtCoralAttribs')}" id="submitCoralAttrib"
                                             oncomplete="handleSaveCoralAttrib(xhr, status, args)"/>
                            <p:commandButton value="#{bundle.btnClose}" oncomplete="dlgCoralAttrib.hide()" icon="ui-icon-document" process="@this" >
                                <pe:resetEditableValues for="displayCoralAttrib"/>
                            </p:commandButton>
                        </f:facet>
                    </h:panelGrid>
                   <p:defaultCommand target="submitCoralAttrib" /> 
                   </h:form>
                </p:dialog> 
            
        
        </ui:composition>    
    </h:body>
</html>
